function [M,C,S,sigma]=train_tsk_type1(X,D,M,sigma,C,S,alpha);
[L,ant]=size(X);
[m,ant]=size(M);

for i=1:L
U=[];
for j=1:m
u=1;
for t=1:ant
u=u*(gaussmf(X(i,t),[sigma(j,1),M(j,1)]));
end
U=[U,u];
end

c2=C(:,1)+S(:,1);
c1=C(:,1)-S(:,1);
for t=1:ant
c2=c2+C(:,t+1)*X(i,t)+S(:,t+1)*abs(X(i,t));
c1=c1+C(:,t+1)*X(i,t)-S(:,t+1)*abs(X(i,t));
end

[r_out,I2l,I2u,wr]= rightpoint(c2',U,U);
[l_out,I1u,I1l,wl]= leftpoint(c1',U,U);
c0=(c1+c2)/2;
f=(l_out+r_out)/2;
fa=U/sum(U);
fa=fa';
e=D(i)-f;
ee(i)=e;
sigma0=sigma;
M0=M;
for l=1:m
for k=1:ant
M(l,k)=M(l,k)+alpha*e*((X(i,k)-M(l,k))/(sigma(l,k)^2))...
*(c0(l)-f)*U(l)/sum(U);
sigma(l,k)=sigma(l,k)+alpha*e*(((X(i,k)-M0(l,k))^2)/(sigma(l,k)^3))...
*(c0(l)-f)*U(l)/sum(U);
end
end


C(:,1)=C(:,1)+alpha*e*fa;
S(:,1)=S(:,1)+alpha*e*fa;

for j=2:(ant+1)
C(:,j)=C(:,j)+alpha*e*X(i,j-1)*fa;
S(:,j)=S(:,j)+alpha*e*abs(X(i,j-1))*fa;
end

end